/**
 * 用来处理用户登陆和注册的JS脚本
 */
function reg()
{
	var accounts = document.getElementById("accounts");
	var appellat = document.getElementById("appellat");
	var password = document.getElementById("password");
	var passworf = document.getElementById("passwordref");
	var emailbox = document.getElementById("emailbox");
	
	if(isNull(accounts))
	{
		mui.toast("请输入您的账号");
		return;
	}
	if(isNull(appellat))
	{
		mui.toast("请输入您的称呼");
		return;
	}
	if(isNull(password))
	{
		mui.toast("请输入您的密码");
		return;
	}
	if(isNull(passworf))
	{
		mui.toast("请确认您的密码");
		return;
	}
	if(isNull(emailbox))
	{
		mui.toast("请输入您的邮箱");
		return;
	}
	
	if(password.value!=passworf.value)
	{
		mui.toast("两次密码输入不一");
		return;
	}
	
	var regEmail = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
	if(!regEmail.test(emailbox.value))
	{
		mui.toast("请输入正确的邮箱信息!");
		return;
	}
	
	var regdata = {
		'B1010'	  :"reg",
		'accounts':accounts.value,
		'appellat':appellat.value,
		'password':password.value,
		'emailbox':emailbox.value,
		}
	m301ajax(regdata);
}

function log()
{	
	var accounts = document.getElementById("accounts");
	var password = document.getElementById("password");
	
	if(isNull(accounts))
	{
		mui.toast("请输入您的账号");
		return;
	}
		if(isNull(password))
	{
		mui.toast("请输入您的密码");
		return;
	}
	
	var logdata = {
		'B1010'	  :'log',
		'accounts':accounts.value,
		'password':password.value,
		}
	
	if(localStorage.getItem('uid')!=null&&localStorage.getItem('uid')!='')
		mui.confirm('请问需要重复登陆吗？','提示：',new Array('否，我点错了','是，重新登陆'),function(e){
			if(e.index==1) {
				m301ajax(logdata);
			}
		});
	else
		m301ajax(logdata);
}

function m301ajax(data)
{
	mui.ajax({
		url	: ASYURI+'B1010.do',
		type: 'POST',
		data: data,
		success	: function(data)
		{
			var obj = eval('('+data+')');
			console.log(obj);
			if(obj.tag=='0'){
				localStorage.setItem('uid',obj.uid);
				mui.toast('登陆成功');
				mui.back();
			}
			else if(obj.tag=='1')
			{
				mui.alert("账号或者密码输入不正确，请检查后重新尝试哦",'提示','确认',function (e) { },'div');
			}
			else if(obj.tag=='2')
			{
				mui.toast('注册成功，将跳回至登陆页面');
				mui.back();
			}
			else if(obj.tag=='3')
			{
				mui.alert('注册失败，原因可能是该账户已经被人使用。','提示','确认',function (e) { },'div');
			}
		},
		error	: function(xhr,type,errorThrown){ mui.toast(xhr+":"+type+"-"+errorThrown); }
	});
}

function isNull(element)
{
	if(element.value==null||element.value=='')
		return true;
}


